import { Body, Controller, Get, Param, Post, UseGuards, Headers } from '@nestjs/common';
import { MineService } from './mine.service';
import { FindMineDiaryDto, FindMineDiaryByUserDto } from './dto/mine.dto';
import { getResponse, ERROR_CODE, ERROR_MESSAGE } from 'src/common/const/const';
import { AuthService } from 'src/services/Auth';

@Controller('mine')
export class MineController {
  constructor(
    private readonly mineService: MineService,
    private readonly authService: AuthService

  ) { }

  @Get('/findDiaryBill')
  async findDiaryBill(@Headers() headers: any) {
    // 日记字符串id创建
    const userInfo = this.authService.checkAuth(headers);
    if (!userInfo) {
      return getResponse(ERROR_CODE.VERIFY_EXPIRE, ERROR_MESSAGE[ERROR_CODE.VERIFY_EXPIRE], {})
    }
    let response = await this.mineService.findDiaryBill(userInfo.userid);
    return getResponse(0, "success", response);
  }

  @Post('/findDiary')
  async findDiary(@Body() findMineDiary: FindMineDiaryDto, @Headers() headers: any) {
    // 日记字符串id创建
    const userInfo = this.authService.checkAuth(headers);
    if (!userInfo) {
      return getResponse(ERROR_CODE.VERIFY_EXPIRE, ERROR_MESSAGE[ERROR_CODE.VERIFY_EXPIRE], {})
    }
    let response = await this.mineService.findDiary(findMineDiary);
    return getResponse(0, "success", response);
  }

  @Post('/findDiaryByUser')
  async findDiaryByUser(@Body() FindMineDiaryByUser: FindMineDiaryByUserDto, @Headers() headers: any) {
    // 日记字符串id创建
    const userInfo = this.authService.checkAuth(headers);
    if (!userInfo) {
      return getResponse(ERROR_CODE.VERIFY_EXPIRE, ERROR_MESSAGE[ERROR_CODE.VERIFY_EXPIRE], {})
    }
    let response = await this.mineService.findDiaryByUser({ userid: userInfo.userid, ...FindMineDiaryByUser });
    return getResponse(0, "success", response);
  }


  @Get('/findMineInfo')
  async findMineInfo(@Headers() headers: any) {
    // 日记字符串id创建
    const userInfo = this.authService.checkAuth(headers);
    if (!userInfo) {
      return getResponse(ERROR_CODE.VERIFY_EXPIRE, ERROR_MESSAGE[ERROR_CODE.VERIFY_EXPIRE], {})
    }
    let response = await this.mineService.findMineInfo(userInfo.userid);
    return getResponse(0, "success", response);
  }
}
